package com.example.orderconsumer.config;

import com.example.orderconsumer.bean.Order;
import com.example.orderconsumer.bean.OrderRequest;
import com.example.orderconsumer.service.OrderService;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class OrderServiceFallbackFactory implements FallbackFactory<OrderService> {
    @Override
    public OrderService create(Throwable cause) {
        return new OrderService() {
            @Override
            public Integer createOrder(OrderRequest request) {
                return -1;
            }
            @Override
            public List<Order> findAll() {
                List<Order> list = new ArrayList<>();
                Order order = new Order();
                order.setId(-1L);
                order.setStatus("Not found");
                list.add(order);
                return list;
            }
        };
    }
}